package com.futureCloudMOM.controller.core.web.basic;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.futureCloudMOM.common.core.domain.AjaxResult;
import com.futureCloudMOM.common.core.page.TableDataInfo;
import com.futureCloudMOM.common.utils.core.QueryWapperDTO;
import com.futureCloudMOM.common.utils.core.QueryWapperUtils;
import com.futureCloudMOM.controller.core.controller.BaseApiController;
import com.futureCloudMOM.core.domain.BasicBillType;
import com.futureCloudMOM.core.domain.BasicBillrule;
import com.futureCloudMOM.core.service.BasicBillruleService;
import com.futureCloudMOM.core.vo.BasicBillRuleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "单据规则",value = "与订单类型关联，根据订单类型生成对应的单据号")
@RestController
@RequestMapping("basic/bill_rule")
public class BasicBillRuleController extends BaseApiController<BasicBillrule, BasicBillrule, BasicBillruleService> {

    public BasicBillRuleController(BasicBillruleService service) {
        super(service);
    }


    @ApiOperation(value = "列表页方法重写")
    @PostMapping("/getListByVO")
    public TableDataInfo getList(BasicBillRuleVO entity, @RequestBody(required = false) List<QueryWapperDTO> list) {
        startPage();
        QueryWrapper<BasicBillRuleVO> queryWrapper = QueryWapperUtils.wapperJojnt(entity, list);
        queryWrapper.eq("deleted", 0);
        queryWrapper.orderByDesc("sysCreateTime");
        return getDataTable(service.getList(queryWrapper));
    }


    @ApiOperation(value = "根据订单类型生成对应的单据号")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "billId", value = "订单类型ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "InvoiceMainId", value = "业务订单主表ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "InvoiceSubId", value = "业务订单子表ID", required = true, dataType = "Long")
    })
    @GetMapping("/getNumber")
    public AjaxResult getNumber(Long billId, Long InvoiceMainId, Long InvoiceSubId) {
        return AjaxResult.success(service.getNumber(billId, InvoiceMainId, InvoiceSubId));
    }

    @ApiOperation(value = "过滤掉添加了单据规则的订单类型")
    @GetMapping("/getBillTypeList")
    public TableDataInfo getBillTypeList(BasicBillType basicBillType) {
        startPage();
        return getDataTable(service.getListByRuleBillTypeId(basicBillType));
    }


}
